<?php
include("admin/controller/config.inc");
//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	
	$passkey=$_GET['passkey'];
	$qry_temp=mysql_query("SELECT * FROM tem_members WHERE confirm_code='$passkey'");
	if($qry_temp){
		$count=mysql_fetch_row($qry_temp);
		if($count==1){
			$row=mysql_fetch_array($qry_temp);
			$fname=$row['f_name'];
			$lname=$row['l_name'];
			$email=$row['email'];
			$pass=$row['password'];
			$gen=$row['gender'];
			$insert_qry=mysql_query("INSERT INTO members(mem_id,f_name,l_name,email,password,gender) VALUES(null,'$fname','$lname','$email','$pass','$gen'");
			if($insert_qry){
				echo "Successfully Registered! Login <a href='login.php'>here</a>:";
				$del_qry=mysql_query("DELETE FROM tem_members WHERE confirm_code='$passkey'");
				
			}
		}
		
	}
	else{
		
		echo "The link has been Expired! You can't use this Link more than once";
	}

?>